package com.sdkj.service.system;

import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Service;

import com.sdkj.dao.DaoSupport;
import com.sdkj.entity.Page;
import com.sdkj.util.PageData;


@Service("sysscheduleService")
public class SysScheduleService {

	@Resource(name = "daoSupport")
	private DaoSupport dao;
	
	/*
	* 新增
	*/
	public void save(PageData pd)throws Exception{
		dao.save("SysScheduleMapper.save", pd);
	}
	
	/*
	* 删除
	*/
	public void delete(PageData pd)throws Exception{
		dao.delete("SysScheduleMapper.delete", pd);
	}
	
	/*
	* 修改
	*/
	public void edit(PageData pd)throws Exception{
		dao.update("SysScheduleMapper.edit", pd);
	}
	
	/*
	*列表
	*/
	public List<PageData> listByDate(PageData pd)throws Exception{
		return (List<PageData>)dao.findForList("SysScheduleMapper.datelist", pd);
	}
	
	/*
	*列表
	*/
	public JSONArray list(PageData pd)throws Exception{
		List<PageData> varList = (List<PageData>)dao.findForList("SysScheduleMapper.datelistAll", pd);
		JSONArray ja = new JSONArray();
		for(PageData schedule : varList){
			JSONObject jo = new JSONObject();
			String title = schedule.getString("schedule_title");
			if(title.length()>15){
				title = title.substring(0, 10)+"...";
			}
			jo.put("schedule_title", title);
			jo.put("title", schedule.getString("schedule_title"));
			jo.put("schedule_id", schedule.getString("schedule_id"));
			ja.add(jo);
		}
		return ja;
	}
	
	/*
	*列表(全部)
	*/
	public List<PageData> listAll(PageData pd)throws Exception{
		return (List<PageData>)dao.findForList("SysScheduleMapper.listAll", pd);
	}
	
	/*
	* 通过id获取数据
	*/
	public PageData findById(PageData pd)throws Exception{
		return (PageData)dao.findForObject("SysScheduleMapper.findById", pd);
	}
	
	/*
	* 批量删除
	*/
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		dao.delete("SysScheduleMapper.deleteAll", ArrayDATA_IDS);
	}
	
}

